//index.js
//获取应用实例
const request =require('../../utils/apifm-wxapi')
Page({
  data: {
    slides:[],
    Sudoku:[],
    shops:[],
  },
  //事件处理函数
  
  onLoad: function () {
    request.banners().then((res)=>{
      console.log(res.data)
      const arr= []
      for(let i=0;i<res.data.length;i++){
        if(res.data[i].title =='首页轮播图'){
          console.log(res.data[i])
          arr.push(res.data[i])
        }
      }
      this.setData({
        slides:arr
      })
      console.log(this.data.slides)
    })
    request.goodsCategory().then((res)=>{
      console.log(res.data)
      this.setData({
        Sudoku:res.data
      })
    })
    request.goods().then((res)=>{
      console.log(res.data)
      this.setData({
        shops:res.data
      })
    })
  },
  detailList(e){
    console.log(e)
    wx.navigateTo({
      url: `/pages/indexList/indexList?id=${e.currentTarget.dataset.id}`,
    })
  },
  search(e){
    console.log(e.detail.value)
    wx.navigateTo({
      url: `/pages/search/search?key=${e.detail.value}`,
    })
  },
  onShow:function(){
    var number = wx.getStorageSync('number')
    if(number!=0){
      wx.setTabBarBadge({
        index: 2,
        text: String(number),
      })
    }else{
      wx.removeTabBarBadge({
        index: 2,
      })
    }
  }
})
